<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 按符号重排数组 -->
    <script>
      var rearange = function (nums) {
        let i = 0
        let j = 1
        let ans = []
        for (let num of nums) {
          if (num > 0) {
            ans[i] = num
            i += 2
          } else {
            ans[j] = num
            j += 2
          }
        }
        return ans
      }
      console.log(rearange([3, 1, -2, -5, 2, -4]))
    </script>
  </body>
</html>
